#!/usr/bin/env python
# encoding: utf-8
"""
@Author: Beam
@Mail:506556658@qq.com
@file: RedisHelper.py
@time: 2017/6/2 14:23
"""

import redis

class RedisHelpers:

    def __init__(self):
        self.pool = redis.ConnectionPool(host='192.168.6.248', port=63780, db=6, password='liang123456')  # 连接池方式连接,用第6这个库
        self.__conn = redis.Redis(connection_pool=self.pool)
        self.chan_sub = 'fm104.5'
        self.chan_pub = 'fm104.5'

    def public(self, msg):
        self.__conn.publish(self.chan_pub, msg)
        return True

    def subscribe(self):
        pub = self.__conn.pubsub()
        pub.subscribe(self.chan_sub)
        pub.parse_response()
        return pub